/**
 * 按业务页面所需数据进行跳转
 */
const getParams = () => {
	const params = uni.getStorageSync("aiParams");
	uni.removeStorageSync("aiParams");
	return params;
}

/**
 * @function 参数处理
 */
export const parseParamsFns = {
	/**
	 * @method (浏览)-(推广/竞标)-专业代办
	 */
	agencyList(componentsContext : any) {
		const params = getParams();
		if (!Object.keys(params)[0]) return;
		try {
			componentsContext.current = params.person_in_country.id //在中国/俄罗斯
			componentsContext.currentnationality = Number(params.person_from_country.id)//国籍
			componentsContext.value1 = params.person_city.citySelect3.label //地区
			componentsContext.listIsShow=true;
		} catch (e) {
			// console.log(e)
		}
	},
	/**
	 * @method (浏览)-(推广/竞标)-跨境货代
	 */
	freightForwarder(componentsContext : any) {
		const params = getParams();
		if (!Object.keys(params)[0]) return;
		const mapping = [//0中国 1俄罗斯
			{ departure_country: 0, reach_country: 0 },
			{ departure_country: 0, reach_country: 1 },
			{ departure_country: 1, reach_country: 0 },
			{ departure_country: 1, reach_country: 1 }
		];
		const { departure_country, reach_country } = mapping[params.departure_reach_country] || { departure_country: 0, reach_country: 0 };
		try {
			componentsContext.CountryofdestinationFrom = departure_country //出发国
			componentsContext.CountryofdestinationArrive = reach_country//目的国
			componentsContext.clearance = params.clearance.id //通关服务
			componentsContext.mode = params.mode.text //运输方式 
			componentsContext.DepartureanddestinationcityFrom = params.departure_city.citySelect3.label//出发城市
			componentsContext.DepartureanddestinationcityArrive = params.reach_city.citySelect3.label //目的城市
			componentsContext.tongguan = params.port_city.citySelect3.label //通关口岸
			componentsContext.freightValue = params.is_express_price.id//公司所在地
			componentsContext.location1 = params.company_city.citySelect3.label //是否含运费
			componentsContext.listIsShow=true;
		} catch (e) {
			// console.log(e);
		}
	},
	/**
	 * @method (浏览)-(推广/竞标)-货物
	 */
	goodsPromotion(componentsContext : any) {
		const params = getParams();
		if (!Object.keys(params)[0]) return;

		try {
			componentsContext.classCurrent = params.goods_type.id //中国货物/俄罗斯货物/在中俄货物/在俄中货 number
			componentsContext.currentCity = params.departure_city.citySelect3.label//所在城市 string
			componentsContext.category = params.category_id.id//商品类型 number
			componentsContext.listIsShow=true;
		} catch (e) {
			// console.log(e);
		}
	},
	/**
	 * @method (浏览)-(推广/竞标)-运输
	 */
	transportList(componentsContext : any) {
		const params = getParams();
		if (!Object.keys(params)[0]) return;

		try {
			const mapping = [//0中国 1俄罗斯
				{ departure_country: "中国", reach_country: "中国" },
				{ departure_country: "中国", reach_country: "俄罗斯" },
				{ departure_country: "俄罗斯", reach_country: "中国" },
				{ departure_country: "俄罗斯", reach_country: "俄罗斯" }
			];
			const { departure_country, reach_country } = mapping[params.departure_reach_country] || { departure_country: 0, reach_country: 0 };
			componentsContext.Countryofdestination = `${departure_country}->${reach_country}`  //出发国 //目的国
			componentsContext.whole_diffuse = params.whole_diffuse.id //整车/散货
			componentsContext.mode = params.mode.id	//运输方式
			componentsContext.fromCity = params.departure_city.citySelect3.label //出发城市
			componentsContext.arriveCity = params.reach_city.citySelect3.label //目的城市
			componentsContext.transportCurrent = params.release_type-1 //选项卡
			console.log(params.release_type)
			componentsContext.listIsShow=true;
		} catch (e) {
			// console.log(e);
		}
	}
}

/**
 * 跳转页面与对应处理函数
 */

export const goTo = (pagePath : string, params : object) => {
	uni.setStorageSync("aiParams", params);
	uni.navigateTo({
		url: pagePath,
	})
}